from aiogram import Dispatcher
from aiogram.dispatcher.filters import CommandStart, CommandHelp, Text, Command
from aiogram.types import ContentType
from aiogram.utils.exceptions import BotBlocked

from app.handlers.addevent import AddEvent, accept_event_data, add_event_start, \
        channel_choosen, date_choosen
from app.handlers.commons import bot_help, bot_start, channel_register
from app.handlers.errors import error_bot_blocked 
from app.handlers.manage_events import display_user_events 


def setup(dp: Dispatcher):
    # Common Handlers
    dp.register_message_handler(bot_start, CommandStart())
    dp.register_message_handler(bot_help, CommandHelp())
    # Add Event handlers
    dp.register_message_handler(add_event_start, Text(equals="Создать анонс"))
    dp.register_channel_post_handler(channel_register, Command('register'))
    dp.register_message_handler(date_choosen, state=AddEvent.waiting_for_date)
    dp.register_callback_query_handler(channel_choosen, Text(startswith="channel_"))
    dp.register_message_handler(
            accept_event_data,
            content_types=[ContentType.PHOTO, ContentType.TEXT],
            state=AddEvent.waiting_for_message
    )
    # Manage Events Handlers
    dp.register_message_handler(display_user_events, Text(equals="Мои анонсы"))
    # Error Handlers
    dp.register_errors_handler(error_bot_blocked, exception=BotBlocked)

